package com.cloudkinto.appletController.file;

import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.file.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Author Administrator
 *
 * @Des
 * @Version
 * @Date 2020/11/18
 */
@RestController
@Api(tags = "小程序文件上传模块")
@RequestMapping("/api/applet/file")
public class AppletFileController extends BaseController {

    @Autowired
    private FileService service;


    //    @UserSessionRequired
    @ApiOperation(value = "附件上传", httpMethod = "POST")
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public SingleResult uploadFile(@RequestParam(value = "file", required = true) MultipartFile file) {
        Long userId = null;
        return service.uploadTempFile(file,userId);
    }

    @ApiOperation(value = "图片上传base64", httpMethod = "POST")
    @RequestMapping(value = "/uploadImageBase64", method = RequestMethod.POST)
    public SingleResult uploadImage(String base64,String fileName) throws Exception {
        return service.uploadImage(base64,fileName);
    }

    @ApiOperation(value = "获取图片", httpMethod = "POST")
    @RequestMapping(value = "/downLoadImage", method = RequestMethod.POST)
    public SingleResult downLoadImage(String fileName) throws Exception {
        return service.downLoadImage(fileName);
    }

}
